import os, sys
import win32print

def printtxt(txt):
  
  printer_name = win32print.GetDefaultPrinter ()
  #
  # raw_data could equally be raw PCL/PS read from
  #  some print-to-file operation
  #
  raw_data=bytes(txt,"utf-8")
  
  hPrinter = win32print.OpenPrinter (printer_name)
  try:
    hJob = win32print.StartDocPrinter (hPrinter, 1, ("LablePrint", None, "RAW"))
    try:
      win32print.StartPagePrinter (hPrinter)
      win32print.WritePrinter (hPrinter, raw_data)
      win32print.EndPagePrinter (hPrinter)
    finally:
      win32print.EndDocPrinter (hPrinter)
  finally:
    win32print.ClosePrinter (hPrinter)

if __name__=="__main__":
  txt="test  "
  printtxt(txt)
